#define _CRT_SECURE_NO_WARNINGS 1
#include <queue>
using namespace std;
  struct TreeNode {
 	int val;
 	struct TreeNode *left;
 	struct TreeNode *right;
 	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
  };
 
class Solution {
public:
    bool isCompleteTree(TreeNode* root)
    {
        queue<TreeNode*> q;
        q.push(root);
        bool flag = false;
        while (!q.empty())
        {
            auto front = q.front();
            q.pop();
            if (front == nullptr)
            {
                flag = true;
                continue;
            }
            if (flag)
            {
                return false;
            }
            q.push(front->left);
            q.push(front->right);
        }
        return true;
    }
};